function toStr(data){
    data.t=Math.random();
    var arr=[];
    for(var name in data){
        arr.push(name+'='+data[name]);
    }
    return arr.join('&');
}
function ajax(url,type,data,success,error){
    if(window.XMLHttpRequest){
        var oAjax=new XMLHttpRequest()
    }else{
        var oAjax=new ActiveXObject('Microsoft.XMLHTTP');
    }

    switch(type.toUpperCase()){
        case 'GET':
            //建立连接
            oAjax.open('GET',url+'?'+toStr(data),true);
            //发送
            oAjax.send();
            break;

        case 'POST':
            oAjax.open('POST',url,true);
            oAjax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            oAjax.send(toStr(data));
    }

    oAjax.onreadystatechange=function(){
        if(oAjax.readyState==4){
            if(oAjax.status>=200 && oAjax.status<300 || oAjax.status==304) {
                success && success(oAjax.responseText);
            }else{
                error && error(oAjax.status);
            }
        }
    };
}